<template>
  <div>
    <el-table
      :data="arr"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号" width="180">
      </el-table-column>
      <el-table-column prop="catename" label="分类名称" width="180">
      </el-table-column>
        <el-table-column prop="img" label="图片" width="180">
      <template slot-scope="scope">

          <img v-if="scope.row.pid!=0" :src="$pre + scope.row.img" alt="" class="Img" width="100%" height="100%"/>
      </template>

        </el-table-column>
      <el-table-column prop="type" label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status === 1"
            >启用</el-button
          >
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="bianji(scope.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" @click="deleteone(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {  reqcatedelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  props: ["arr"],
  data() {
    return {};
  },
  methods: {
    bianji(id) {
      this.$emit("info", id);
    },
    deleteone(id) {
      this.$confirm("你确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //点了确定
          reqcatedelete({
            id: id,
          }).then((res) => {
            if (res.data.code === 200) {
              //弹成功
              successAlert(res.data.msg);
              //重新请求列表
              this.$emit("init");
            }
          });
        })
        .catch(() => {
          //点了取消
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
      
    },
  },
};
</script>

<style>
.Img{
  overflow: hidden;
}
</style>
